package com.jd.controller;

import java.util.Date;
import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jd.entity.MessageEntity;
import com.jd.entity.SignUpEntity;
import com.jd.service.MatchService;
import com.jd.service.MessageService;
import com.jd.service.SignUpService;
import com.jd.service.TicketService;
import com.jd.util.IdUtil;

@Controller
@RequestMapping("/signUpController")
public class SignUpController {

	@Autowired
	private SignUpService signUpService;
	@Autowired
	private MatchService matchService;
	@Autowired
	private MessageService messageService;
	@Autowired
	private TicketService ticketService;
	
	//报名
	@RequestMapping("/signUp")
	@ResponseBody
	public String signUp(HttpServletRequest request){
		String userId = request.getSession().getAttribute("userId").toString();
		String matchId = request.getParameter("id");
		String roleNick = request.getParameter("roleNick");
		String id=IdUtil.getIdByUUId();
		SignUpEntity signUpEntity = new SignUpEntity();
		signUpEntity.setId(id);
		signUpEntity.setCreateBy(userId);
		signUpEntity.setCreateTime(new Date());
		signUpEntity.setDelflag("0");
		signUpEntity.setMatchId(matchId);
		signUpEntity.setStart("0");
		signUpEntity.setUserId(userId);
		signUpEntity.setRemark8(roleNick);
		signUpEntity.setRemark9("0");
		signUpEntity.setRemark10("0");
		String i=signUpService.signUp(signUpEntity);
		return i;
	}
	//点击连接了
	@RequestMapping("/updateStart")
	@ResponseBody
	public Boolean updateStart(HttpServletRequest request){
		String userId = request.getSession().getAttribute("userId").toString();
		String matchId = request.getParameter("id");
		SignUpEntity signUpEntity = new SignUpEntity();
		signUpEntity.setMatchId(matchId);
		signUpEntity.setStart("1");
		signUpEntity.setUserId(userId);
		Boolean i=signUpService.updateStart(signUpEntity);
		return i;
	}
	
	@RequestMapping("/getSignUp")
	@ResponseBody
	public SignUpEntity getSignUp(HttpServletRequest request){
		String userId = request.getSession().getAttribute("userId").toString();
		String matchId = request.getParameter("id");
		SignUpEntity signUpEntity = new SignUpEntity();
		signUpEntity.setMatchId(matchId);
		signUpEntity.setUserId(userId);
		SignUpEntity signUp=signUpService.getSignUp(signUpEntity);
		return signUp;
	}
}
